package state.util;

import state.util.array.StringArray;

public class TwoDimensionString {
  private StringArray data = null;
  private int width = 0;
  private int height = 0;
  
  public TwoDimensionString(int width1, int height1) {
    data = StringArray.create(width1 * height1);
    for (int i = 0; i < data.len(); i++) {
      data.set(i, "");
    }
    width = width1;
    height = height1;
  }
  
  public String get(int column, int row) {
    return data.get(row * width + column);
  }
  
  public void set(int column, int row, String value) {
    data.set(row * width + column, value);
  }
  
  public StringArray getRow(int rowIndex) {
    StringArray row = StringArray.create(width);
    for (int i = 0; i < row.len(); i++) {
      row.set(i, data.get(rowIndex * width + i));
    }
    return row;
  }
  
  public void setRow(int rowIndex, StringArray row) {
    for (int i = 0; i < row.len(); i++) {
      data.set(rowIndex * width + i, row.get(i));
    }
  }
  
  public void setColumn(int columnIndex, StringArray column) {
    for (int i = 0; i < column.len(); i++) {
      data.set(i * width + columnIndex, column.get(i));
    }
  }
  
  public int getWidth() {
    return width;
  }
  
  public int getHeight() {
    return height;
  }
}
